/**
 * 广寒宫
 * 网址:www.guanghangong.xyz
 */
package com.moon.admin.flowable.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.moon.admin.flowable.entity.FlowModelUserEntity;
import com.moon.admin.flowable.mapper.FlowModelUserMapper;

/**
 * 流程绑定用户
 * @author ninglong
 * @date 2020年2月11日
 */
@Service
public class FlowModelUserService extends ServiceImpl<FlowModelUserMapper, FlowModelUserEntity>{
	
	@Transactional
	public void binding(String modelKey,String category,List<Integer> userIdList) {
		//先删除
		this.remove(Wrappers.<FlowModelUserEntity>lambdaQuery().eq(FlowModelUserEntity::getModelKey, modelKey).eq(FlowModelUserEntity::getFlowTypeId, category));
		//批量添加
		List<FlowModelUserEntity> list = Lists.newArrayList();
		for(Integer userId:userIdList) {
			FlowModelUserEntity flowUser = FlowModelUserEntity.builder().modelKey(modelKey).userId(userId).flowTypeId(category).build();
			list.add(flowUser);
		}
		this.saveBatch(list);
	}
}
